package com.gr.controller;

import com.gr.entity.Brand;
import com.gr.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @RequestMapping("/selectAllBrand")
    public String selectAllBrand(Model model){
        List<Brand> brands = brandService.selectAllBrand();
        model.addAttribute("brands",brands);
        return "/addPhone.jsp";
    }
    @RequestMapping("/selectAllBrandAndPhoneNum")
    public String selectAllBrandAndPhoneNum(Model model){
        List<Brand> brands = brandService.selectAllBrandAndPhoneNum();
        model.addAttribute("brands",brands);
        return "/brand_list.jsp";
    }
    @RequestMapping("/addBrand") //底层方法没有书写
    public String addBrand(Model model,Brand brand){
        brandService.addBrand(brand);
        return "/brand/selectAllBrandAndPhoneNum.do";
    }
    @RequestMapping("/deleteBrand")
    public String deleteBrand(Model model,Integer id){
        brandService.deleteBrandById(id);
        return "/brand/selectAllBrandAndPhoneNum.do";
    }
}
